package file_io;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
public class FileIoMain {

	private ArrayList<String> outputList = new ArrayList();
	
	public FileIoMain()
	{
		outputList.add("学号：040411214");
		outputList.add("姓名：邹恩岑");
		outputList.add("运动：爬山");
		for (int i = 0; i < 1000; i++)
		{
			String morning ="Good Morning";
			outputList.add(morning + i);
		}
	}
	
	public void readFile(String file_path) throws IOException
	{
		File file;
		FileReader fr;
		BufferedReader br;

		file = new File(file_path);
		if (!file.exists()){
			System.out.println("\""+file_path+"\" does not exsit!");
			return;
		}
		
		fr = new FileReader(file);
		br = new BufferedReader(fr);
		String str = " ";
		 if(br.ready())
         {
            br.read();
         }
//		while(br.readLine() != null){
//			str = br.readLine();
//			System.out.println(str);
//		}
		while(br.ready()){
			str = br.readLine();
			System.out.println(str);
		}
		br.close();
	}

	public void writeFile(String file_path) throws IOException
	{
		File file;
		FileWriter fw;
		PrintWriter pw;

		file = new File(file_path);
		if (!file.exists()){
			file.createNewFile();
		}
		fw = new FileWriter(file);
		pw = new PrintWriter(fw);
		
		for(String str : outputList){
			pw.write(str+"\n\r");
		}
		
		pw.close();
	}
	public static void main(String[] args) throws IOException {
		FileIoMain io = new FileIoMain();
		io.readFile("d:/hw3_input.txt");
		io.writeFile("d:/hw3_output.txt");
	}
}
